package controler;

import appli.Dynamizer;
import modele.SimulationConway;
import modele.interfaces.SimulationAbstract;
import modele.interfaces.SimulationInterface;
import controler.interfaces.ControlerAbstract;
import controler.interfaces.ControlerInterface;
import controler.interfaces.MainControlerInterface;
import controler.interfaces.ModelControlerInterface;
import controler.interfaces.ViewControleurInterface;

public class MainControler extends ControlerAbstract implements
		MainControlerInterface {

	private boolean timeToRun;
	private ModelControlerInterface modelControler;
	private ViewControleurInterface viewControler;

	public MainControler() {
		setName();
		timeToRun = true;
	}

	@Override
	public SimulationInterface injectModel() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setName() {
		setName("Main_Controler");
	}

	@Override
	public void askRunSim(String simName) {

		if (timeToRun) {

			Dynamizer dyn = new Dynamizer("./simulations/" + simName + ".txt");
			dyn.parse();
			String parameters = "";
			String simulation = "";
			SimulationInterface simul = createSimulation(simName);
			String cases = "";
			String agents = "";

			modelControler.launch(simul);
		}
	}

	private SimulationInterface createSimulation(String sim) {
		SimulationInterface simul;
		if (sim != "") {
			simul = new SimulationConway(sim);
			return simul;
		}
		return null;
	}

	@Override
	public void init(ControlerInterface controler,
			ModelControlerInterface modelControler,
			ViewControleurInterface viewControler) {
		super.init(controler);
		this.modelControler = modelControler;
		this.viewControler = viewControler;

	}

	@Override
	public void quit() {
		modelControler.quit();
		controler.quit();

	}

	@Override
	public void triggerAStep() {
		modelControler.triggerAStep();

	}

	@Override
	public void switchStepByStep() {
		modelControler.switchStepByStep();

	}

}
